<?php 
include 'method/win.php';
// 查热门
$hotsql = "SELECT weibo_user.user_tx, weibo_list.* FROM weibo_user, weibo_list WHERE weibo_user.user_name = weibo_list.author AND weibo_list.weibo_img != '' ORDER by weibo_list.weibo_hot desc";
$hotres = $conn->query($hotsql);

if(!isset($_GET['page'])){
    $page = 1;
}else{
    $page = $_GET['page'];
}

$hotper_page = 40;
if(!isset($_GET['hotpage'])){
    $hotpage = 1;
}else{
    $hotpage = $_GET['hotpage'];
}

$hottotal_ly = $hotres->num_rows;
$hottotal_page = ceil($hottotal_ly/$hotper_page);

$hotsql = "SELECT weibo_user.user_tx, weibo_list.* FROM weibo_user, weibo_list WHERE weibo_user.user_name = weibo_list.author AND weibo_list.weibo_img != ''  ORDER by weibo_list.weibo_hot desc limit ".($hotpage-1)*$hotper_page.",".$hotper_page;
$hotres = $conn->query($hotsql);
// 查最新
$newsql = "select weibo_user.user_tx, weibo_list.* FROM weibo_user, weibo_list WHERE weibo_list.weibo_img != '' AND weibo_user.user_name=weibo_list.author ORDER BY weibo_list.public_time DESC";
$newres = $conn->query($newsql);

$newper_page = 40;
if(!isset($_GET['newpage'])){
    $newpage = 1;
}else{
    $newpage = $_GET['newpage'];
}

$newtotal_ly = $newres->num_rows;
$newtotal_page = ceil($newtotal_ly/$newper_page);

$newsql = "select weibo_user.user_tx, weibo_list.* FROM weibo_user, weibo_list WHERE weibo_list.weibo_img != '' AND weibo_user.user_name=weibo_list.author ORDER BY weibo_list.public_time DESC limit ".($newpage-1)*$newper_page.",".$newper_page;
$newres = $conn->query($newsql);

if(isset($_SESSION['user'])){
    header("location:index_loginafter.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>小狗简易微博</title>
    <link rel="stylesheet" href="../lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/index.css">
    <script src="../lib/jquery/jquery.js" type="text/javascript"></script>
    <script src="../lib/bootstrap/js/bootstrap.js" type="text/javascript"></script>
</head>
<body>

<!--顶部导航条-->
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!--头部logo-->
        <div class="navbar-header">
            <a class="navbar-brand" href="#"><em><img src="../img/logo.jpg" height=30 width=30></em><em>小狗微博</em></a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <!--搜索-->
            <form class="navbar-form navbar-left" role="search" method="post" action="search.php">
                <div class="form-group">
                    <input type="text" class="form-control" style="width: 400px" placeholder="Search" name="str-search">
                </div>
                <button type="sumbit" class="btn btn-default" name="search-btn">搜索</button>
            </form>
            <!--首页、注册登录-->
            <ul class="nav navbar-nav navbar-right">
                <li><a href="index.php">首页</a></li>
                <li><a href="register.php">注册</a></li>
                <li><a href="login.php">登录</a></li>

            </ul>
        </div>
    </div>
</nav>

<!--首页版心-->
<div class="index-warp clearfix">
    <!--左边导航-->
    <div class="nav-left">
        <ul class="list-group a-color">
            <a href='index.php?page=1'><li class="list-group-item choose-1" id="nav-1">热门</li></a>
            <a href='index.php?page=2'><li class="list-group-item" id="nav-2">最新</li></a>
        </ul>
    </div>

    <!--中间内容部分-->
    <!--热门部分-->
    <div class="hot-warp choose-2 clearfix">
        <div class="tip-bar"><span>当前为热门部分</span></div>
        
        <?php 
        while ($row = $hotres->fetch_assoc()){
//             微博链接
            echo "<a href='detail.php?id=".$row['weibo_id']."'>";
//             微博盒子
            echo "<div class='weibo-box clearfix'>";
//             微博图片
            echo "<div class='weibo-photo'>";
            echo "<img src='../".$row['weibo_img']."'>";
            echo "</div>";
//             微博文本
            echo "<div class='content-weibo'>".$row['weibo_content']."</div>";
//             用户名及日期
            echo "<div class='username-weibo'>";
            echo "<img src='../".$row['user_tx']."' style='width: 20px; height: 20px; border-radius: 50%'>";
            echo "<span class='username-info'>".$row['author']."</span>&nbsp;";
            echo "<span class='time-public'>".$row['public_time']."</span>";
            echo "</div>";
            
            $csql = "select * from weibo_comment where weibo_id = ".$row['weibo_id'];
            $cres = $conn->query($csql);
            $kcsql = "select * from weibo_kidcomment where weibo_id=".$row['weibo_id'];
            $kcres = $conn->query($kcsql);
            $cnum = ($cres->num_rows)+($kcres->num_rows);
            
            $rsql = "select * from weibo_list where relwb_id = ".$row['weibo_id'];
            $rres = $conn->query($rsql);
            
//             微博转发、评论、点赞
            echo "<div class='op-weibo'>";
            echo "<span><em class='glyphicon glyphicon-share'></em><em>".$rres->num_rows."</em></span>";
            echo "<span>|</span>";
            echo "<span><em class='glyphicon glyphicon-comment'></em><em>".$cnum."</em></span>";
            echo "<span>|</span>";
            echo "<span><em class='glyphicon glyphicon-thumbs-up'></em><em>".$row['weibo_zan']."</em></span>";
            echo "</div>";
            echo "</div>";
            echo "</a>";
        }
//         加载更多
        if($hottotal_page!="1"){
            if($hotpage==1){
                echo "<div class='loadmore clearfix'>";
                echo "<a href='index.php?page=1&hotpage=1'>";
                echo "<span>首页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=1'>";
                echo "<span>上一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=".($hotpage+1)."'>";
                echo "<span>下一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=".$hottotal_page."'>";
                echo "<span>尾页</span>";
                echo "</a>";
                echo "</div>";
            }else if($hotpage==$hottotal_page){
                echo "<div class='loadmore clearfix'>";
                echo "<a href='index.php?page=1&hotpage=1'>";
                echo "<span>首页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=".($hotpage-1)."'>";
                echo "<span>上一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=".$hottotal_page."'>";
                echo "<span>下一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=".$hottotal_page."'>";
                echo "<span>尾页</span>";
                echo "</a>";
                echo "</div>";
            }else {
                echo "<div class='loadmore clearfix'>";
                echo "<a href='index.php?page=1&hotpage=1'>";
                echo "<span>首页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=".($hotpage-1)."'>";
                echo "<span>上一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=".($hotpage+1)."'>";
                echo "<span>下一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=1&hotpage=".$hottotal_page."'>";
                echo "<span>尾页</span>";
                echo "</a>";
                echo "</div>";
            }
        }
        
        
        ?>

    </div>

    <!--最新部分-->
    <div class="new-warp clearfix">
        <div class="tip-bar"><span>当前为最新部分</span></div>
        
        <?php 
        $no = 1;
        while ($row = $newres->fetch_assoc()){
//             微博链接
            echo "<a href='detail.php?id=".$row['weibo_id']."'>";
//             微博盒子
            echo "<div class='weibo-box clearfix'>";
//             微博图片
            echo "<div class='weibo-photo'>";
            echo "<img src='../".$row['weibo_img']."'>";
            echo "</div>";
//             微博文本
            echo "<div class='content-weibo'>".$row['weibo_content']."</div>";
//             用户名及日期
            echo "<div class='username-weibo'>";
            echo "<img src='../".$row['user_tx']."' style='width: 20px; height: 20px; border-radius: 50%'>";
            echo "<span class='username-info'>".$row['author']."</span>&nbsp;";
            echo "<span class='time-public'>".$row['public_time']."</span>";
            echo "</div>";
            
            $csql = "select * from weibo_comment where weibo_id = ".$row['weibo_id'];
            $cres = $conn->query($csql);
            $kcsql = "select * from weibo_kidcomment where weibo_id=".$row['weibo_id'];
            $kcres = $conn->query($kcsql);
            $cnum = ($cres->num_rows)+($kcres->num_rows);
            
            $rsql = "select * from weibo_list where relwb_id = ".$row['weibo_id'];
            $rres = $conn->query($rsql);
//             微博转发、评论、点赞
            echo "<div class='op-weibo'>";
            echo "<span><em class='glyphicon glyphicon-share'></em><em>".$rres->num_rows."</em></span>";
            echo "<span>|</span>";
            echo "<span><em class='glyphicon glyphicon-comment'></em><em>".$cnum."</em></span>";
            echo "<span>|</span>";
            echo "<span><em class='glyphicon glyphicon-thumbs-up'></em><em>".$row['weibo_zan']."</em></span>";
            echo "</div>";
            echo "</div>";
            echo "</a>";
        }
//         加载更多
        if($newtotal_page!="1"){
            if($newpage==1){
                echo "<div class='loadmore clearfix'>";
                echo "<a href='index.php?page=2&newpage=1'>";
                echo "<span>首页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=1'>";
                echo "<span>上一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=".($newpage+1)."'>";
                echo "<span>下一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=".$newtotal_page."'>";
                echo "<span>尾页</span>";
                echo "</a>";
                echo "</div>";
            }else if($newpage==$newtotal_page){
                echo "<div class='loadmore clearfix'>";
                echo "<a href='index.php?page=2&newpage=1'>";
                echo "<span>首页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=".($newpage-1)."'>";
                echo "<span>上一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=".$newtotal_page."'>";
                echo "<span>下一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=".$newtotal_page."'>";
                echo "<span>尾页</span>";
                echo "</a>";
                echo "</div>";
            }else {
                echo "<div class='loadmore clearfix'>";
                echo "<a href='index.php?page=2&newpage=1'>";
                echo "<span>首页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=".($newpage-1)."'>";
                echo "<span>上一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=".($newpage+1)."'>";
                echo "<span>下一页</span>";
                echo "</a>";
                echo "<a href='index.php?page=2&newpage=".$newtotal_page."'>";
                echo "<span>尾页</span>";
                echo "</a>";
                echo "</div>";
            }
        }
        ?>
    </div>

    <div class="right-warp">
        <div class="logo">
            <img src="../img/logo1.jpg" style="width: 260px; height: 260px">
        </div>
    </div>
</div>
</body>
<!--脚本-->
<script>
    // 点击左边导航条跳转页面
    	if(<?php echo $page?>=="2"){
    		$(".list-group-item").removeClass("choose-1")
            $("#nav-2").addClass("choose-1")
            $(".new-warp").removeClass("choose-2")
            $(".hot-warp").removeClass("choose-2")
            $(".new-warp").addClass("choose-2")
        }else {
            $(".list-group-item").removeClass("choose-1")
            $("#nav-1").addClass("choose-1")
            $(".hot-warp").removeClass("choose-2")
            $(".new-warp").removeClass("choose-2")
            $(".hot-warp").addClass("choose-2")
        }
</script>
</html>